package com.ruoyi.web.controller.purchase;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.purchase.domain.PoPurchase;
import com.ruoyi.purchase.service.PoPurchaseService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 采购单审核 Controller
 */
@Controller
@RequestMapping("/purchase/check")
public class PurchaseCheckController extends BaseController {
    private String prefix= "purchase/check/";

    @Autowired
    private PoPurchaseService poPurchaseService;

    @RequiresPermissions("purchase:check:view")
    @RequestMapping()
    public String purCheck(){
        return prefix+"purCheck";
    }

    @RequiresPermissions("purchase:check:list")
    @RequestMapping("/list")
    @ResponseBody
    public TableDataInfo list(PoPurchase poPurchase){
        startPage();
        List<PoPurchase> poPurCheckList= poPurchaseService.findPurCheckList(poPurchase);
        System.out.println(poPurCheckList);
        return getDataTable(poPurCheckList);
    }

    @RequiresPermissions("purchase:check:check")
    @RequestMapping("/check/{id}")
    public String check(@PathVariable("id") String id, Model model){
        PoPurchase purchase = poPurchaseService.getById(id);
        System.out.println(purchase);
        model.addAttribute("purchase",purchase);
        model.addAttribute("pUser",getSysUser());
        return prefix+"check";
    }
    //@RequiresPermissions("purchase:check:check")
    @RequestMapping("/doCheck")
    @ResponseBody
    public AjaxResult doCheck(@Validated PoPurchase poPurchase){
        System.out.println(poPurchase);
        return toAjax(poPurchaseService.updateById(poPurchase));
    }



}
